/*
 * MoveThought.cpp
 *
 *  Created on: 05-01-2011
 *      Author: Piotr
 */

#include "AI/thoughts/MoveThought.hpp"

MoveThought::MoveThought() :
	direction(Vector()), length(0.0f)
{
}

MoveThought::MoveThought(const Vector& moveVector) :
	direction(moveVector), length(moveVector.getLength())
{
}

MoveThought::MoveThought(const Vector& direction, float length) :
	direction(direction), length(length)
{
}

MoveThought::~MoveThought()
{

}

const Vector& MoveThought::getDirection()
{
	return direction;
}

void MoveThought::setDirection(const Vector& direction)
{
	this->direction = direction;
}

float MoveThought::getLength() const
{
	return length;
}

Vector MoveThought::getMoveVector() const
{
	if(!MathUtils::isNearZero(direction.getX()) && !MathUtils::isNearZero(direction.getY()))
	{
		return direction.normalize() * length;
	}
	return Vector();
}

void MoveThought::execute(Individual* individual)
{
	if(!MathUtils::isNearZero(direction.getX()) && !MathUtils::isNearZero(direction.getY()))
	{
		const Vector& normalized = direction.normalize();
		individual->setPosition(individual->getPosition() + normalized * length);
		individual->getState().setLookDirection(normalized);
	}
}

